home *** CD-ROM | disk | FTP | other *** search
- Path: info.uah.edu!oreo!gbacon
- From: gbacon@oreo (Greg Bacon)
- Newsgroups: comp.lang.c
- Subject: Re: GoTo equivalent in C ??
- Date: 13 Jan 1996 02:00:05 GMT
- Organization: The University of Alabama in Huntsville
- Message-ID: <4d73n5$88a@info.uah.edu>
- References: <4d67vm$e5h@masala.cc.uh.edu>
- NNTP-Posting-Host: oreo.aspire.cs.uah.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- sukumar (sukku@menudo.uh.edu) wrote:
- : Hi,
- : I have always thought about this. How do you get the effect of goto
- : in C without using "goto"?? For ex, if I have to check for an error in my
- : function for every computation I do, and then do some cleaning up, how do
- : I do it. Here is an example:
-
- [snip]
-
- : I don't want to use goto. what alternatievs do I have.
- : Any ideas are greatly appreciated.
-
- : -Srini.
-
- There is no goof reason not to use goto _judiciously_. (Note the qualifier
- to all you would-be holy war initiators!) To quote the FAQ:
-
- "In the case of the goto statement, it has long been observed
- that unfettered use of goto's quickly leads to unmaintainable
- spaghetti code."
-
- Ahh, the wisdom of those words. However, a real programmer isn't afraid
- to use goto (when it doesn't threaten her job security :) If you are
- so truly opposed to goto, then you can get the same effect with an
- extra variable like so:
-
- int stay = 0;
-
- while (stay == 0)
- {
- if exit condition is true {
- /* you would goto here */
- stay++;
- }
-
- The thing about the purely structured approach is that you have to design
- some pretty tight loops at times which cut into your speed efficiency.
- Here's something to think about: what machine language do you know of that
- doesn't have a JMP instruction? People who adhere strictly to the principles
- of structured programming are just like those who say that humans aren't
- animals. People are just as much animals as programming is about goto's.
-
- Food for thought :)
- Greg
- --
- Greg Bacon <gbacon@cs.uah.edu>
- University of Alabama in Huntsville
- CS Department Systems Support Team
-